package com.ruoyi.lm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lm.domain.LmUserinvention;
import com.ruoyi.lm.service.ILmUserinventionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 邀请好友Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/lm/userinvention")
public class LmUserinventionController extends BaseController
{
    private String prefix = "lm/userinvention";

    @Autowired
    private ILmUserinventionService lmUserinventionService;

    @RequiresPermissions("lm:userinvention:view")
    @GetMapping()
    public String userinvention()
    {
        return prefix + "/userinvention";
    }

    /**
     * 查询邀请好友列表
     */
    @RequiresPermissions("lm:userinvention:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmUserinvention lmUserinvention)
    {
        startPage();
        List<LmUserinvention> list = lmUserinventionService.selectLmUserinventionList(lmUserinvention);
        return getDataTable(list);
    }

    /**
     * 导出邀请好友列表
     */
    @RequiresPermissions("lm:userinvention:export")
    @Log(title = "邀请好友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LmUserinvention lmUserinvention)
    {
        List<LmUserinvention> list = lmUserinventionService.selectLmUserinventionList(lmUserinvention);
        ExcelUtil<LmUserinvention> util = new ExcelUtil<LmUserinvention>(LmUserinvention.class);
        return util.exportExcel(list, "userinvention");
    }

    /**
     * 新增邀请好友
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存邀请好友
     */
    @RequiresPermissions("lm:userinvention:add")
    @Log(title = "邀请好友", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LmUserinvention lmUserinvention)
    {
        return toAjax(lmUserinventionService.insertLmUserinvention(lmUserinvention));
    }

    /**
     * 修改邀请好友
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LmUserinvention lmUserinvention = lmUserinventionService.selectLmUserinventionById(id);
        mmap.put("lmUserinvention", lmUserinvention);
        return prefix + "/edit";
    }

    /**
     * 修改保存邀请好友
     */
    @RequiresPermissions("lm:userinvention:edit")
    @Log(title = "邀请好友", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LmUserinvention lmUserinvention)
    {
        return toAjax(lmUserinventionService.updateLmUserinvention(lmUserinvention));
    }

    /**
     * 删除邀请好友
     */
    @RequiresPermissions("lm:userinvention:remove")
    @Log(title = "邀请好友", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmUserinventionService.deleteLmUserinventionByIds(ids));
    }
}
